﻿using Bankomat.States.AbstractStates;
using System.Windows.Forms;

namespace Bankomat.UserInterface
{
    public class Display
    {
        private Label myCenterLabel;

        private Label myLeftLabel1;
        private Label myLeftLabel2;
        private Label myLeftLabel3;
        private Label myLeftLabel4;

        private Label myRightLabel1;
        private Label myRightLabel2;
        private Label myRightLabel3;
        private Label myRightLabel4;

        private Button myCardReader;

        public Display(Label CenterLabel, Label leftLabel1, Label leftLabel2, Label leftLabel3,  Label leftLabel4, 
            Label rightLabel1, Label rightLabel2, Label rightLabel3, Label rightLabel4, Button CardReader)
        {
            this.myCenterLabel = CenterLabel;

            this.myLeftLabel1 = leftLabel1;
            this.myLeftLabel2 = leftLabel2;
            this.myLeftLabel3 = leftLabel3;
            this.myLeftLabel4 = leftLabel4;

            this.myRightLabel1 = rightLabel1;
            this.myRightLabel2 = rightLabel2;
            this.myRightLabel3 = rightLabel3;
            this.myRightLabel4 = rightLabel4;

            this.myCardReader = CardReader;
        }

        public void Show(ActionState state)
        {
            HideLabel(myCenterLabel);

            HideLabel(myLeftLabel1);
            HideLabel(myLeftLabel2);
            HideLabel(myLeftLabel3);
            HideLabel(myLeftLabel4);

            HideLabel(myRightLabel1);
            HideLabel(myRightLabel2);
            HideLabel(myRightLabel3);
            HideLabel(myRightLabel4);

            ShowText(myLeftLabel1, state.OptionLeft1);
            ShowText(myLeftLabel2, state.OptionLeft2);
            ShowText(myLeftLabel3, state.OptionLeft3);
            ShowText(myLeftLabel4, state.OptionLeft4);

            ShowText(myRightLabel1, state.OptionRight1);
            ShowText(myRightLabel2, state.OptionRight2);
            ShowText(myRightLabel3, state.OptionRight3);
            ShowText(myRightLabel4, state.OptionRight4);

            CardStatus(state.CardIsIn);
        }

        public void Show(InfoState state)
        {
            HideLabel(myCenterLabel);

            HideLabel(myLeftLabel1);
            HideLabel(myLeftLabel2);
            HideLabel(myLeftLabel3);
            HideLabel(myLeftLabel4);

            HideLabel(myRightLabel1);
            HideLabel(myRightLabel2);
            HideLabel(myRightLabel3);
            HideLabel(myRightLabel4);

            ShowText(myCenterLabel, state.InfoMessage);
            ShowText(myRightLabel4, state.OptionRight4);

            CardStatus(state.CardIsIn);
        }

        private void ShowText(Label label, string text)
        {
            label.Visible = true;
            label.Text = text;
        }

        private void HideLabel(Label label)
        {
            label.Visible = false;
        }

        private void CardStatus(bool CardIsIn)
        {
            if (CardIsIn)
            {
                myCardReader.Text = "Remove Card";
            }
            else
            {
                myCardReader.Text = "Insert Card";
            }
        }
    }
}
